package com.ironman.imes.device.framework.web.adapter;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

public class WhitespaceRemovalAdapter extends TypeAdapter<String> {
    @Override
    public void write(JsonWriter out, String value) throws IOException {
        if (value == null) {
            out.nullValue();
            return;
        }
        // 移除所有空白字符（包括 \r\n\t）
        String cleaned = value.replaceAll("\\s+", " ");
        out.value(cleaned.trim());
    }
    @Override
    public String read(JsonReader in) throws IOException {
        return in.nextString();
    }
}